<!DOCTYPE HTML>
<html lang="zh-tw" >
    <!-- Start book python高级 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>多继承和MRO顺序 | python高级</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-emphasize/plugin.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../day12/02.property.html" />
    
    
    <link rel="prev" href="../day12/00.readme.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="2.1"
        data-chapter-title="多继承和MRO顺序"
        data-filepath="day12/01.mro.md"
        data-basepath=".."
        data-revision="Wed Sep 26 2018 22:46:13 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Python高级
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="day11/00.readme.html">
            
                
                    <a href="../day11/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        Python语法高级专题1
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="day11/01.GIL.html">
            
                
                    <a href="../day11/01.GIL.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        GIL问题
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="day11/02.copy.html">
            
                
                    <a href="../day11/02.copy.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        赋值-浅拷贝-深拷贝
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="day11/03.import.html">
            
                
                    <a href="../day11/03.import.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        import导入模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="day11/04.review.html">
            
                
                    <a href="../day11/04.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="day12/00.readme.html">
            
                
                    <a href="../day12/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        Python语法高级专题2
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="2.1" data-path="day12/01.mro.html">
            
                
                    <a href="../day12/01.mro.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        多继承和MRO顺序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="day12/02.property.html">
            
                
                    <a href="../day12/02.property.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        property属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="day12/03.magic.html">
            
                
                    <a href="../day12/03.magic.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        魔法属性和方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="day12/04.with.html">
            
                
                    <a href="../day12/04.with.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        with管理上下文
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="day12/05.review.html">
            
                
                    <a href="../day12/05.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="day13/00.readme.html">
            
                
                    <a href="../day13/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Python语法之装饰器
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="day13/01.closure.html">
            
                
                    <a href="../day13/01.closure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        闭包
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="day13/02.decorator.html">
            
                
                    <a href="../day13/02.decorator.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        装饰器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="day13/03.review.html">
            
                
                    <a href="../day13/03.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="day14/00.readme.html">
            
                
                    <a href="../day14/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        MySQL数据库基本操作
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="day14/01.数据库概述.html">
            
                
                    <a href="../day14/01.数据库概述.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        数据库概述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="day14/02.数据类型和约束.html">
            
                
                    <a href="../day14/02.数据类型和约束.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        数据完整性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="day14/03.Navicat.html">
            
                
                    <a href="../day14/03.Navicat.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        图形化客户端Navicat
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="day14/04.命令行客户端.html">
            
                
                    <a href="../day14/04.命令行客户端.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        命令行客户端SQL的使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.4.1" data-path="day14/05.sql_con.html">
            
                
                    <a href="../day14/05.sql_con.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.1.</b>
                        
                        登录和退出数据库
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.2" data-path="day14/07.sql_table_struct.html">
            
                
                    <a href="../day14/07.sql_table_struct.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.2.</b>
                        
                        表结构的操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.3" data-path="day14/06.sql_database.html">
            
                
                    <a href="../day14/06.sql_database.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.3.</b>
                        
                        数据库的操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.4" data-path="day14/08.表数据操作.html">
            
                
                    <a href="../day14/08.表数据操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.4.</b>
                        
                        表数据的操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="day14/09.review.html">
            
                
                    <a href="../day14/09.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        知识总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="day15/00.readme.html">
            
                
                    <a href="../day15/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        MYSQL数据库进阶操作
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="day15/01.练习.html">
            
                
                    <a href="../day15/01.练习.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        练习强化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="day15/02.where条件.html">
            
                
                    <a href="../day15/02.where条件.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        条件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="day15/03.排序查询.html">
            
                
                    <a href="../day15/03.排序查询.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        排序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="day15/04.分页查询.html">
            
                
                    <a href="../day15/04.分页查询.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        分页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="day15/05.聚合函数.html">
            
                
                    <a href="../day15/05.聚合函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        聚合函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="day15/06.分组.html">
            
                
                    <a href="../day15/06.分组.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        分组
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="day15/07.连接.html">
            
                
                    <a href="../day15/07.连接.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        连接
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="day15/08.自连接.html">
            
                
                    <a href="../day15/08.自连接.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        自连接
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="day15/09.子查询.html">
            
                
                    <a href="../day15/09.子查询.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        子查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.10" data-path="day15/10.总结.html">
            
                
                    <a href="../day15/10.总结.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.10.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="day16/readme.html">
            
                
                    <a href="../day16/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        MYSQL数据库编程
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="day16/data.html">
            
                
                    <a href="../day16/data.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        数据准备
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="day16/sql_code.html">
            
                
                    <a href="../day16/sql_code.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        SQL演练
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="day16/dbdesign.html">
            
                
                    <a href="../day16/dbdesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        数据库设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="day16/pymysql.html">
            
                
                    <a href="../day16/pymysql.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        数据库编程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="day16/zongjie.html">
            
                
                    <a href="../day16/zongjie.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="day17/00.readme.html">
            
                
                    <a href="../day17/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        MySQL数据库高级用法
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="day17/01.view.html">
            
                
                    <a href="../day17/01.view.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        视图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="day17/02.transaction.html">
            
                
                    <a href="../day17/02.transaction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        事务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="day17/03.sql_index.html">
            
                
                    <a href="../day17/03.sql_index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        索引
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="day17/04.user.html">
            
                
                    <a href="../day17/04.user.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        用户管理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="day17/05.master_slave.html">
            
                
                    <a href="../day17/05.master_slave.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        主从配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="day17/06.review.html">
            
                
                    <a href="../day17/06.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.6.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="day18/00.readme.html">
            
                
                    <a href="../day18/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        miniweb框架
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="day18/01.框架是什么.html">
            
                
                    <a href="../day18/01.框架是什么.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        框架概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="day18/02.实现框架.html">
            
                
                    <a href="../day18/02.实现框架.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        实现一个简单的框架
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="day18/03.模板.html">
            
                
                    <a href="../day18/03.模板.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        模板替换
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="day18/04.路由.html">
            
                
                    <a href="../day18/04.路由.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        路由概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="day18/05.显示股票数据.html">
            
                
                    <a href="../day18/05.显示股票数据.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        股票收藏夹
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="day18/05.review.html">
            
                
                    <a href="../day18/05.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        复习
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本書使用 GitBook 釋出
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >python高级</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="1&#x591A;&#x7EE7;&#x627F;&#x4EE5;&#x53CA;mro&#x987A;&#x5E8F;">1.&#x591A;&#x7EE7;&#x627F;&#x4EE5;&#x53CA;MRO&#x987A;&#x5E8F;</h1>
<h2 id="11-&#x5B66;&#x4E60;&#x76EE;&#x6807;">1.1 &#x5B66;&#x4E60;&#x76EE;&#x6807;</h2>
<ul>
<li>&#x77E5;&#x9053;&#x591A;&#x7EE7;&#x627F;&#x7684;&#x7279;&#x5F81;</li>
<li>&#x80FD;&#x591F;&#x8BF4;&#x51FA;MRO&#x987A;&#x5E8F;&#x7684;&#x4F5C;&#x7528;</li>
<li>&#x80FD;&#x591F;&#x8BF4;&#x51FA;super&#x7684;&#x4F5C;&#x7528;</li>
</ul>
<h2 id="12-&#x5355;&#x72EC;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;&#x65B9;&#x6CD5;">1.2 &#x5355;&#x72EC;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;&#x65B9;&#x6CD5;</h2>
<blockquote>
<p>&#x6839;&#x636E;&#x6211;&#x4EEC;&#x4E4B;&#x524D;&#x5B66;&#x4E60;&#x7684;&#x77E5;&#x8BC6;&#x53EF;&#x4EE5;&#x77E5;&#x9053;&#xFF0C;<strong>&#x5728;&#x5B50;&#x7C7B;&#x521D;&#x59CB;&#x5316;&#x7684;&#x65F6;&#x5019;&#x9700;&#x8981;&#x624B;&#x52A8;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;&#x521D;&#x59CB;&#x5316;&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x7236;&#x7C7B;&#x7684;&#x5C5E;&#x6027;&#x7684;&#x6784;&#x9020;&#xFF0C;&#x4E0D;&#x7136;&#x5C31;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;&#x63D0;&#x4F9B;&#x7684;&#x5C5E;&#x6027;</strong>&#x3002;</p>
<p>&#x5728;&#x5B50;&#x7C7B;&#x4E2D;&#x5982;&#x4F55;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;&#x521D;&#x59CB;&#x5316;&#x65B9;&#x6CD5;&#x5462; 
    &#x7236;&#x7C7B;&#x540D;.__init__(self)</p>
<p>&#x4EC0;&#x4E48;&#x662F;&#x591A;&#x7EE7;&#x627F;
    &#x4E00;&#x4E2A;&#x5B50;&#x7C7B;&#x540C;&#x65F6;&#x7EE7;&#x627F;&#x81EA;&#x591A;&#x4E2A;&#x7236;&#x7C7B;&#xFF0C;&#x53C8;&#x79F0;&#x83F1;&#x5F62;&#x7EE7;&#x627F;&#x3001;&#x94BB;&#x77F3;&#x7EE7;&#x627F;&#x3002;</p>
</blockquote>
<pre><code class="lang-python"><span class="hljs-comment"># coding=utf-8</span>

print(<span class="hljs-string">&quot;******&#x591A;&#x7EE7;&#x627F;&#x4F7F;&#x7528;&#x7C7B;&#x540D;.__init__ &#x53D1;&#x751F;&#x7684;&#x72B6;&#x6001;******&quot;</span>)
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Parent</span><span class="hljs-params">(object)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name)</span>:</span>
        print(<span class="hljs-string">&apos;parent&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;&apos;</span>)
        self.name = name
        print(<span class="hljs-string">&apos;parent&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;&apos;</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Son1</span><span class="hljs-params">(Parent)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name, age)</span>:</span>
        print(<span class="hljs-string">&apos;Son1&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;&apos;</span>)
        self.age = age
        Parent.__init__(self, name)
        print(<span class="hljs-string">&apos;Son1&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;&apos;</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Son2</span><span class="hljs-params">(Parent)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name, gender)</span>:</span>
        print(<span class="hljs-string">&apos;Son2&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;&apos;</span>)
        self.gender = gender
        Parent.__init__(self, name)
        print(<span class="hljs-string">&apos;Son2&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;&apos;</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Grandson</span><span class="hljs-params">(Son1, Son2)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name, age, gender)</span>:</span>
        print(<span class="hljs-string">&apos;Grandson&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;&apos;</span>)
        Son1.__init__(self, name, age)  <span class="hljs-comment"># &#x5355;&#x72EC;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;&#x521D;&#x59CB;&#x5316;&#x65B9;&#x6CD5;</span>
        Son2.__init__(self, name, gender)
        print(<span class="hljs-string">&apos;Grandson&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;&apos;</span>)

gs = Grandson(<span class="hljs-string">&apos;grandson&apos;</span>, <span class="hljs-number">12</span>, <span class="hljs-string">&apos;&#x7537;&apos;</span>)
print(<span class="hljs-string">&apos;&#x59D3;&#x540D;&#xFF1A;&apos;</span>, gs.name)
print(<span class="hljs-string">&apos;&#x5E74;&#x9F84;&#xFF1A;&apos;</span>, gs.age)
print(<span class="hljs-string">&apos;&#x6027;&#x522B;&#xFF1A;&apos;</span>, gs.gender)

print(<span class="hljs-string">&quot;******&#x591A;&#x7EE7;&#x627F;&#x4F7F;&#x7528;&#x7C7B;&#x540D;.__init__ &#x53D1;&#x751F;&#x7684;&#x72B6;&#x6001;******\n\n&quot;</span>)
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;:</p>
<pre><code>******&#x591A;&#x7EE7;&#x627F;&#x4F7F;&#x7528;&#x7C7B;&#x540D;.__init__ &#x53D1;&#x751F;&#x7684;&#x72B6;&#x6001;******
Grandson&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;
Son1&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;
parent&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;
parent&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;
Son1&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;
Son2&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;
parent&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;
parent&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;
Son2&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;
Grandson&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;
&#x59D3;&#x540D;&#xFF1A; grandson
&#x5E74;&#x9F84;&#xFF1A; 12
&#x6027;&#x522B;&#xFF1A; &#x7537;
******&#x591A;&#x7EE7;&#x627F;&#x4F7F;&#x7528;&#x7C7B;&#x540D;.__init__ &#x53D1;&#x751F;&#x7684;&#x72B6;&#x6001;******
</code></pre><h2 id="13-mro&#x987A;&#x5E8F;">1.3 MRO&#x987A;&#x5E8F;</h2>
<pre><code>&#x901A;&#x8FC7;&#x4E0A;&#x8FF0;&#x4EE3;&#x7801;&#xFF0C;&#x6211;&#x4EEC;&#x53D1;&#x73B0;&#x7531;&#x4E8E;&#x591A;&#x7EE7;&#x627F;&#x60C5;&#x51B5;&#xFF0C;parent&#x7C7B;&#x88AB;&#x7684;&#x5C5E;&#x6027;&#x88AB;&#x6784;&#x9020;&#x4E86;&#x4E24;&#x6B21;&#xFF0C;&#x5982;&#x679C;&#x5728;&#x66F4;&#x52A0;&#x590D;&#x6742;&#x7684;&#x7ED3;&#x6784;&#x4E0B;&#x53EF;&#x80FD;&#x66F4;&#x52A0;&#x4E25;&#x91CD;&#x3002;
&#x4E3A;&#x4E86;&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;Python&#x5B98;&#x65B9;&#x91C7;&#x7528;&#x4E86;&#x4E00;&#x4E2A;&#x7B97;&#x6CD5;&#x5C06;&#x590D;&#x6742;&#x7ED3;&#x6784;&#x4E0A;&#x6240;&#x6709;&#x7684;&#x7C7B;&#x5168;&#x90E8;&#x90FD;&#x6620;&#x5C04;&#x5230;&#x4E00;&#x4E2A;&#x7EBF;&#x6027;&#x987A;&#x5E8F;&#x4E0A;&#xFF0C;&#x800C;&#x6839;&#x636E;&#x8FD9;&#x4E2A;&#x987A;&#x5E8F;&#x5C31;&#x80FD;**&#x591F;&#x4FDD;&#x8BC1;&#x6240;&#x6709;&#x7684;&#x7C7B;&#x90FD;&#x4F1A;&#x88AB;&#x6784;&#x9020;&#x4E00;&#x6B21;**&#x3002;
&#x8FD9;&#x4E2A;&#x987A;&#x5E8F;&#x5C31;&#x662F;MRO&#x987A;&#x5E8F;&#x3002;
</code></pre><blockquote>
<p>&#x67E5;&#x770B;MRO&#x987A;&#x5E8F;</p>
<pre><code>* &#x7C7B;&#x540D;.__mro__()
* &#x7C7B;&#x540D;.mro()
</code></pre></blockquote>
<h2 id="14-&#x591A;&#x7EE7;&#x627F;&#x4E2D;super&#x8C03;&#x7528;&#x6709;&#x6240;&#x7236;&#x7C7B;&#x7684;&#x88AB;&#x91CD;&#x5199;&#x7684;&#x65B9;&#x6CD5;">1.4 &#x591A;&#x7EE7;&#x627F;&#x4E2D;super&#x8C03;&#x7528;&#x6709;&#x6240;&#x7236;&#x7C7B;&#x7684;&#x88AB;&#x91CD;&#x5199;&#x7684;&#x65B9;&#x6CD5;</h2>
<p><strong>    super&#x672C;&#x8D28;&#x4E0A;&#x5C31;&#x662F;&#x4F7F;&#x7528;MRO&#x8FD9;&#x4E2A;&#x987A;&#x5E8F;&#x53BB;&#x8C03;&#x7528; &#x5F53;&#x524D;&#x7C7B;&#x5728;MRO&#x987A;&#x5E8F;&#x4E2D;&#x4E0B;&#x4E00;&#x4E2A;&#x7C7B;&#x3002;
</strong>    super().__init__()&#x5219;&#x8C03;&#x7528;&#x4E86;&#x4E0B;&#x4E00;&#x4E2A;&#x7C7B;&#x7684;&#x521D;&#x59CB;&#x5316;&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x6784;&#x9020;&#x3002;</p>
<pre><code class="lang-python">print(<span class="hljs-string">&quot;******&#x591A;&#x7EE7;&#x627F;&#x4F7F;&#x7528;super().__init__ &#x53D1;&#x751F;&#x7684;&#x72B6;&#x6001;******&quot;</span>)
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Parent</span><span class="hljs-params">(object)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name, *args, **kwargs)</span>:</span>  <span class="hljs-comment"># &#x4E3A;&#x907F;&#x514D;&#x591A;&#x7EE7;&#x627F;&#x62A5;&#x9519;&#xFF0C;&#x4F7F;&#x7528;&#x4E0D;&#x5B9A;&#x957F;&#x53C2;&#x6570;&#xFF0C;&#x63A5;&#x53D7;&#x53C2;&#x6570;</span>
        print(<span class="hljs-string">&apos;parent&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;&apos;</span>)
        self.name = name
        print(<span class="hljs-string">&apos;parent&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;&apos;</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Son1</span><span class="hljs-params">(Parent)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name, age, *args, **kwargs)</span>:</span>  <span class="hljs-comment"># &#x4E3A;&#x907F;&#x514D;&#x591A;&#x7EE7;&#x627F;&#x62A5;&#x9519;&#xFF0C;&#x4F7F;&#x7528;&#x4E0D;&#x5B9A;&#x957F;&#x53C2;&#x6570;&#xFF0C;&#x63A5;&#x53D7;&#x53C2;&#x6570;</span>
        print(<span class="hljs-string">&apos;Son1&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;&apos;</span>)
        self.age = age
        super().__init__(name, *args, **kwargs)  <span class="hljs-comment"># &#x4E3A;&#x907F;&#x514D;&#x591A;&#x7EE7;&#x627F;&#x62A5;&#x9519;&#xFF0C;&#x4F7F;&#x7528;&#x4E0D;&#x5B9A;&#x957F;&#x53C2;&#x6570;&#xFF0C;&#x63A5;&#x53D7;&#x53C2;&#x6570;</span>
        print(<span class="hljs-string">&apos;Son1&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;&apos;</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Son2</span><span class="hljs-params">(Parent)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name, gender, *args, **kwargs)</span>:</span>  <span class="hljs-comment"># &#x4E3A;&#x907F;&#x514D;&#x591A;&#x7EE7;&#x627F;&#x62A5;&#x9519;&#xFF0C;&#x4F7F;&#x7528;&#x4E0D;&#x5B9A;&#x957F;&#x53C2;&#x6570;&#xFF0C;&#x63A5;&#x53D7;&#x53C2;&#x6570;</span>
        print(<span class="hljs-string">&apos;Son2&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;&apos;</span>)
        self.gender = gender
        super().__init__(name, *args, **kwargs)  <span class="hljs-comment"># &#x4E3A;&#x907F;&#x514D;&#x591A;&#x7EE7;&#x627F;&#x62A5;&#x9519;&#xFF0C;&#x4F7F;&#x7528;&#x4E0D;&#x5B9A;&#x957F;&#x53C2;&#x6570;&#xFF0C;&#x63A5;&#x53D7;&#x53C2;&#x6570;</span>
        print(<span class="hljs-string">&apos;Son2&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;&apos;</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Grandson</span><span class="hljs-params">(Son1, Son2)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name, age, gender)</span>:</span>
        print(<span class="hljs-string">&apos;Grandson&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;&apos;</span>)
        <span class="hljs-comment"># &#x591A;&#x7EE7;&#x627F;&#x65F6;&#xFF0C;&#x76F8;&#x5BF9;&#x4E8E;&#x4F7F;&#x7528;&#x7C7B;&#x540D;.__init__&#x65B9;&#x6CD5;&#xFF0C;&#x8981;&#x628A;&#x6BCF;&#x4E2A;&#x7236;&#x7C7B;&#x5168;&#x90E8;&#x5199;&#x4E00;&#x904D;</span>
        <span class="hljs-comment"># &#x800C;super&#x53EA;&#x7528;&#x4E00;&#x53E5;&#x8BDD;&#xFF0C;&#x6267;&#x884C;&#x4E86;&#x5168;&#x90E8;&#x7236;&#x7C7B;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x4E5F;&#x662F;&#x4E3A;&#x4F55;&#x591A;&#x7EE7;&#x627F;&#x9700;&#x8981;&#x5168;&#x90E8;&#x4F20;&#x53C2;&#x7684;&#x4E00;&#x4E2A;&#x539F;&#x56E0;</span>
        <span class="hljs-comment"># super(Grandson, self).__init__(name, age, gender)</span>
        super().__init__(name, age, gender)
        print(<span class="hljs-string">&apos;Grandson&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;&apos;</span>)

print(Grandson.__mro__)

gs = Grandson(<span class="hljs-string">&apos;grandson&apos;</span>, <span class="hljs-number">12</span>, <span class="hljs-string">&apos;&#x7537;&apos;</span>)
print(<span class="hljs-string">&apos;&#x59D3;&#x540D;&#xFF1A;&apos;</span>, gs.name)
print(<span class="hljs-string">&apos;&#x5E74;&#x9F84;&#xFF1A;&apos;</span>, gs.age)
print(<span class="hljs-string">&apos;&#x6027;&#x522B;&#xFF1A;&apos;</span>, gs.gender)
print(<span class="hljs-string">&quot;******&#x591A;&#x7EE7;&#x627F;&#x4F7F;&#x7528;super().__init__ &#x53D1;&#x751F;&#x7684;&#x72B6;&#x6001;******\n\n&quot;</span>)
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code>******&#x591A;&#x7EE7;&#x627F;&#x4F7F;&#x7528;super().__init__ &#x53D1;&#x751F;&#x7684;&#x72B6;&#x6001;******
(&lt;class &apos;__main__.Grandson&apos;&gt;, &lt;class &apos;__main__.Son1&apos;&gt;, &lt;class &apos;__main__.Son2&apos;&gt;, &lt;class &apos;__main__.Parent&apos;&gt;, &lt;class &apos;object&apos;&gt;)
Grandson&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;
Son1&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;
Son2&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;
parent&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;
parent&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;
Son2&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;
Son1&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;
Grandson&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;
&#x59D3;&#x540D;&#xFF1A; grandson
&#x5E74;&#x9F84;&#xFF1A; 12
&#x6027;&#x522B;&#xFF1A; &#x7537;
******&#x591A;&#x7EE7;&#x627F;&#x4F7F;&#x7528;super().__init__ &#x53D1;&#x751F;&#x7684;&#x72B6;&#x6001;******
</code></pre><h2 id="&#x6CE8;&#x610F;&#xFF1A;">&#x6CE8;&#x610F;&#xFF1A;</h2>
<blockquote>
<ol>
<li>&#x4EE5;&#x4E0A;2&#x4E2A;&#x4EE3;&#x7801;&#x6267;&#x884C;&#x7684;&#x7ED3;&#x679C;&#x4E0D;&#x540C;</li>
<li>&#x5982;&#x679C;2&#x4E2A;&#x5B50;&#x7C7B;&#x4E2D;&#x90FD;&#x7EE7;&#x627F;&#x4E86;&#x7236;&#x7C7B;&#xFF0C;&#x5F53;&#x5728;&#x5B50;&#x7C7B;&#x4E2D;&#x901A;&#x8FC7;&#x7236;&#x7C7B;&#x540D;&#x8C03;&#x7528;&#x65F6;&#xFF0C;parent&#x88AB;&#x6267;&#x884C;&#x4E86;2&#x6B21;</li>
<li>&#x5982;&#x679C;2&#x4E2A;&#x5B50;&#x7C7B;&#x4E2D;&#x90FD;&#x7EE7;&#x627F;&#x4E86;&#x7236;&#x7C7B;&#xFF0C;&#x5F53;&#x5728;&#x5B50;&#x7C7B;&#x4E2D;&#x901A;&#x8FC7;super&#x8C03;&#x7528;&#x65F6;&#xFF0C;parent&#x88AB;&#x6267;&#x884C;&#x4E86;1&#x6B21;</li>
</ol>
</blockquote>
<h2 id="15-&#x5355;&#x7EE7;&#x627F;&#x4E2D;super">1.5 &#x5355;&#x7EE7;&#x627F;&#x4E2D;super</h2>
<pre><code class="lang-python">
print(<span class="hljs-string">&quot;******&#x5355;&#x7EE7;&#x627F;&#x4F7F;&#x7528;super().__init__ &#x53D1;&#x751F;&#x7684;&#x72B6;&#x6001;******&quot;</span>)
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Parent</span><span class="hljs-params">(object)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name)</span>:</span>
        print(<span class="hljs-string">&apos;parent&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;&apos;</span>)
        self.name = name
        print(<span class="hljs-string">&apos;parent&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;&apos;</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Son1</span><span class="hljs-params">(Parent)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name, age)</span>:</span>
        print(<span class="hljs-string">&apos;Son1&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;&apos;</span>)
        self.age = age
        super().__init__(name)  <span class="hljs-comment"># &#x5355;&#x7EE7;&#x627F;&#x4E0D;&#x80FD;&#x63D0;&#x4F9B;&#x5168;&#x90E8;&#x53C2;&#x6570;</span>
        print(<span class="hljs-string">&apos;Son1&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;&apos;</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Grandson</span><span class="hljs-params">(Son1)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name, age, gender)</span>:</span>
        print(<span class="hljs-string">&apos;Grandson&#x7684;init&#x5F00;&#x59CB;&#x88AB;&#x8C03;&#x7528;&apos;</span>)
        super().__init__(name, age)  <span class="hljs-comment"># &#x5355;&#x7EE7;&#x627F;&#x4E0D;&#x80FD;&#x63D0;&#x4F9B;&#x5168;&#x90E8;&#x53C2;&#x6570;</span>
        print(<span class="hljs-string">&apos;Grandson&#x7684;init&#x7ED3;&#x675F;&#x88AB;&#x8C03;&#x7528;&apos;</span>)

gs = Grandson(<span class="hljs-string">&apos;grandson&apos;</span>, <span class="hljs-number">12</span>, <span class="hljs-string">&apos;&#x7537;&apos;</span>)
print(<span class="hljs-string">&apos;&#x59D3;&#x540D;&#xFF1A;&apos;</span>, gs.name)
print(<span class="hljs-string">&apos;&#x5E74;&#x9F84;&#xFF1A;&apos;</span>, gs.age)
<span class="hljs-comment">#print(&apos;&#x6027;&#x522B;&#xFF1A;&apos;, gs.gender)</span>
print(<span class="hljs-string">&quot;******&#x5355;&#x7EE7;&#x627F;&#x4F7F;&#x7528;super().__init__ &#x53D1;&#x751F;&#x7684;&#x72B6;&#x6001;******\n\n&quot;</span>)
</code></pre>
<h2 id="16-&#x603B;&#x7ED3;">1.6 &#x603B;&#x7ED3;</h2>
<ol>
<li>MRO&#x4FDD;&#x8BC1;&#x4E86;&#x591A;&#x7EE7;&#x627F;&#x60C5;&#x51B5; &#x6BCF;&#x4E2A;&#x7C7B;&#x53EA;&#x51FA;&#x73B0;&#x4E00;&#x6B21;</li>
<li>super().__init__&#x76F8;&#x5BF9;&#x4E8E;&#x7C7B;&#x540D;.__init__&#xFF0C;&#x5728;&#x5355;&#x7EE7;&#x627F;&#x4E0A;&#x7528;&#x6CD5;&#x57FA;&#x672C;&#x65E0;&#x5DEE;</li>
<li>&#x4F46;&#x5728;&#x591A;&#x7EE7;&#x627F;&#x4E0A;&#x6709;&#x533A;&#x522B;&#xFF0C;super&#x65B9;&#x6CD5;&#x80FD;&#x4FDD;&#x8BC1;&#x6BCF;&#x4E2A;&#x7236;&#x7C7B;&#x7684;&#x65B9;&#x6CD5;&#x53EA;&#x4F1A;&#x6267;&#x884C;&#x4E00;&#x6B21;&#xFF0C;&#x800C;&#x4F7F;&#x7528;&#x7C7B;&#x540D;&#x7684;&#x65B9;&#x6CD5;&#x4F1A;&#x5BFC;&#x81F4;&#x65B9;&#x6CD5;&#x88AB;&#x6267;&#x884C;&#x591A;&#x6B21;</li>
<li>&#x591A;&#x7EE7;&#x627F;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;super&#x65B9;&#x6CD5;&#xFF0C;&#x5BF9;&#x7236;&#x7C7B;&#x7684;&#x4F20;&#x53C2;&#x6570;&#xFF0C;&#x5E94;&#x8BE5;&#x662F;&#x7531;&#x4E8E;python&#x4E2D;super&#x7684;&#x7B97;&#x6CD5;&#x5BFC;&#x81F4;&#x7684;&#x539F;&#x56E0;&#xFF0C;&#x5FC5;&#x987B;&#x628A;&#x53C2;&#x6570;&#x5168;&#x90E8;&#x4F20;&#x9012;&#xFF0C;&#x5426;&#x5219;&#x4F1A;&#x62A5;&#x9519;</li>
<li>&#x5355;&#x7EE7;&#x627F;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;super&#x65B9;&#x6CD5;&#xFF0C;&#x5219;&#x4E0D;&#x80FD;&#x5168;&#x90E8;&#x4F20;&#x9012;&#xFF0C;&#x53EA;&#x80FD;&#x4F20;&#x7236;&#x7C7B;&#x65B9;&#x6CD5;&#x6240;&#x9700;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x5426;&#x5219;&#x4F1A;&#x62A5;&#x9519;</li>
<li>&#x591A;&#x7EE7;&#x627F;&#x65F6;&#xFF0C;&#x76F8;&#x5BF9;&#x4E8E;&#x4F7F;&#x7528;&#x7C7B;&#x540D;.__init__&#x65B9;&#x6CD5;&#xFF0C;&#x8981;&#x628A;&#x6BCF;&#x4E2A;&#x7236;&#x7C7B;&#x5168;&#x90E8;&#x5199;&#x4E00;&#x904D;, &#x800C;&#x4F7F;&#x7528;super&#x65B9;&#x6CD5;&#xFF0C;&#x53EA;&#x9700;&#x5199;&#x4E00;&#x53E5;&#x8BDD;&#x4FBF;&#x6267;&#x884C;&#x4E86;&#x5168;&#x90E8;&#x7236;&#x7C7B;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x4E5F;&#x662F;&#x4E3A;&#x4F55;&#x591A;&#x7EE7;&#x627F;&#x9700;&#x8981;&#x5168;&#x90E8;&#x4F20;&#x53C2;&#x7684;&#x4E00;&#x4E2A;&#x539F;&#x56E0;</li>
</ol>
<h2 id="&#x5C0F;&#x8BD5;&#x725B;&#x5200;&#x4EE5;&#x4E0B;&#x4E3A;&#x9762;&#x8BD5;&#x9898;">&#x5C0F;&#x8BD5;&#x725B;&#x5200;(&#x4EE5;&#x4E0B;&#x4E3A;&#x9762;&#x8BD5;&#x9898;)</h2>
<blockquote>
<p>&#x4EE5;&#x4E0B;&#x7684;&#x4EE3;&#x7801;&#x7684;&#x8F93;&#x51FA;&#x5C06;&#x662F;&#x4EC0;&#x4E48;? &#x8BF4;&#x51FA;&#x4F60;&#x7684;&#x7B54;&#x6848;&#x5E76;&#x89E3;&#x91CA;&#x3002;</p>
</blockquote>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Parent</span><span class="hljs-params">(object)</span>:</span>
    x = <span class="hljs-number">1</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Child1</span><span class="hljs-params">(Parent)</span>:</span>
    <span class="hljs-keyword">pass</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Child2</span><span class="hljs-params">(Parent)</span>:</span>
    <span class="hljs-keyword">pass</span>

print(Parent.x, Child1.x, Child2.x)
Child1.x = <span class="hljs-number">2</span>
print(Parent.x, Child1.x, Child2.x)
Parent.x = <span class="hljs-number">3</span>
print(Parent.x, Child1.x, Child2.x)
</code></pre>
<p>&#x7B54;&#x6848;, &#x4EE5;&#x4E0A;&#x4EE3;&#x7801;&#x7684;&#x8F93;&#x51FA;&#x662F;&#xFF1A;</p>
<pre><code>1 1 1
1 2 1
3 2 3
</code></pre><p>&#x4F7F;&#x4F60;&#x56F0;&#x60D1;&#x6216;&#x662F;&#x60CA;&#x5947;&#x7684;&#x662F;&#x5173;&#x4E8E;&#x6700;&#x540E;&#x4E00;&#x884C;&#x7684;&#x8F93;&#x51FA;&#x662F; 3 2 3 &#x800C;&#x4E0D;&#x662F; 3 2 1&#x3002;&#x4E3A;&#x4EC0;&#x4E48;&#x6539;&#x53D8;&#x4E86; Parent.x &#x7684;&#x503C;&#x8FD8;&#x4F1A;&#x6539;&#x53D8; Child2.x &#x7684;&#x503C;&#xFF0C;&#x4F46;&#x662F;&#x540C;&#x65F6; Child1.x &#x503C;&#x5374;&#x6CA1;&#x6709;&#x6539;&#x53D8;&#xFF1F;</p>
<p>&#x8FD9;&#x4E2A;&#x7B54;&#x6848;&#x7684;&#x5173;&#x952E;&#x662F;&#xFF0C;&#x5728; Python &#x4E2D;&#xFF0C;&#x7C7B;&#x53D8;&#x91CF;&#x5728;&#x5185;&#x90E8;&#x662F;&#x4F5C;&#x4E3A;&#x5B57;&#x5178;&#x5904;&#x7406;&#x7684;&#x3002;&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x7684;&#x540D;&#x5B57;&#x6CA1;&#x6709;&#x5728;&#x5F53;&#x524D;&#x7C7B;&#x7684;&#x5B57;&#x5178;&#x4E2D;&#x53D1;&#x73B0;&#xFF0C;&#x5C06;&#x641C;&#x7D22;&#x7956;&#x5148;&#x7C7B;&#xFF08;&#x6BD4;&#x5982;&#x7236;&#x7C7B;&#xFF09;&#x76F4;&#x5230;&#x88AB;&#x5F15;&#x7528;&#x7684;&#x53D8;&#x91CF;&#x540D;&#x88AB;&#x627E;&#x5230;&#xFF08;&#x5982;&#x679C;&#x8FD9;&#x4E2A;&#x88AB;&#x5F15;&#x7528;&#x7684;&#x53D8;&#x91CF;&#x540D;&#x65E2;&#x6CA1;&#x6709;&#x5728;&#x81EA;&#x5DF1;&#x6240;&#x5728;&#x7684;&#x7C7B;&#x53C8;&#x6CA1;&#x6709;&#x5728;&#x7956;&#x5148;&#x7C7B;&#x4E2D;&#x627E;&#x5230;&#xFF0C;&#x4F1A;&#x5F15;&#x53D1;&#x4E00;&#x4E2A; AttributeError &#x5F02;&#x5E38; &#xFF09;&#x3002;</p>
<p>&#x56E0;&#x6B64;&#xFF0C;&#x5728;&#x7236;&#x7C7B;&#x4E2D;&#x8BBE;&#x7F6E; x = 1 &#x4F1A;&#x4F7F;&#x5F97;&#x7C7B;&#x53D8;&#x91CF; x &#x5728;&#x5F15;&#x7528;&#x8BE5;&#x7C7B;&#x548C;&#x5176;&#x4EFB;&#x4F55;&#x5B50;&#x7C7B;&#x4E2D;&#x7684;&#x503C;&#x4E3A; 1&#x3002;&#x8FD9;&#x5C31;&#x662F;&#x56E0;&#x4E3A;&#x7B2C;&#x4E00;&#x4E2A; print &#x8BED;&#x53E5;&#x7684;&#x8F93;&#x51FA;&#x662F; 1 1 1&#x3002;</p>
<p>&#x968F;&#x540E;&#xFF0C;&#x5982;&#x679C;&#x4EFB;&#x4F55;&#x5B83;&#x7684;&#x5B50;&#x7C7B;&#x91CD;&#x5199;&#x4E86;&#x8BE5;&#x503C;&#xFF08;&#x4F8B;&#x5982;&#xFF0C;&#x6211;&#x4EEC;&#x6267;&#x884C;&#x8BED;&#x53E5; Child1.x = 2&#xFF09;&#xFF0C;&#x7136;&#x540E;&#xFF0C;&#x8BE5;&#x503C;&#x4EC5;&#x4EC5;&#x5728;&#x5B50;&#x7C7B;&#x4E2D;&#x88AB;&#x6539;&#x53D8;&#x3002;&#x8FD9;&#x5C31;&#x662F;&#x4E3A;&#x4EC0;&#x4E48;&#x7B2C;&#x4E8C;&#x4E2A; print &#x8BED;&#x53E5;&#x7684;&#x8F93;&#x51FA;&#x662F; 1 2 1&#x3002;</p>
<p>&#x6700;&#x540E;&#xFF0C;&#x5982;&#x679C;&#x8BE5;&#x503C;&#x5728;&#x7236;&#x7C7B;&#x4E2D;&#x88AB;&#x6539;&#x53D8;&#xFF08;&#x4F8B;&#x5982;&#xFF0C;&#x6211;&#x4EEC;&#x6267;&#x884C;&#x8BED;&#x53E5; Parent.x = 3&#xFF09;&#xFF0C;&#x8FD9;&#x4E2A;&#x6539;&#x53D8;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x4EFB;&#x4F55;&#x672A;&#x91CD;&#x5199;&#x8BE5;&#x503C;&#x7684;&#x5B50;&#x7C7B;&#x5F53;&#x4E2D;&#x7684;&#x503C;&#xFF08;&#x5728;&#x8FD9;&#x4E2A;&#x793A;&#x4F8B;&#x4E2D;&#x88AB;&#x5F71;&#x54CD;&#x7684;&#x5B50;&#x7C7B;&#x662F; Child2&#xFF09;&#x3002;&#x8FD9;&#x5C31;&#x662F;&#x4E3A;&#x4EC0;&#x4E48;&#x7B2C;&#x4E09;&#x4E2A; print &#x8F93;&#x51FA;&#x662F; 3 2 3&#x3002;</p>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../day12/00.readme.html" class="navigation navigation-prev " aria-label="Previous page: Python语法高级专题2"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../day12/02.property.html" class="navigation navigation-next " aria-label="Next page: property属性"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"toggle-chapters":{},"splitter":{},"emphasize":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book python高级 -->
</html>
